<template>
	<view>
		<u-loading-page :loading="pageLoading"></u-loading-page>
		<view class="nav" :style="navStyle">
			<view class="back-btn" @click="goBack">
				<text class="ri-arrow-left-s-line" style="font-size: 17px;"></text>
			</view>
		</view>
		<scroll-view scroll-y="true" :style="{height: '100vh'}" :scroll-top="scrollTop" @scroll="onScroll"
			v-if="!pageLoading">
			<view class="first-screen" :style="{backgroundImage: `url(${info.mainBanner.imageUrl})`}">
				<view class="text">
					<view style="color:white;font-size:16px;font-weight: bold;">{{info.mainBanner.text}}</view>
					<view class="mt-20 title" style="color:white;font-size:40px;font-weight: bold;">镇川镇</view>
					<view class="mt-30" style="color:#eeeeee;font-size:14px">{{info.mainBanner.description}}</view>
					<view class="mt-30" style="display: flex;justify-content: flex-end;">
						<div class="circle" @click="scrollToNextSection">
							<text class="ri-arrow-down-s-line" style="font-size:26px"></text>
						</div>
					</view>
				</view>
			</view>
			<!--历史文化 -->
			<view class="section">
				<view class="page-title">
					<view class="text">{{info.historyCultures.title}}</view>
				</view>
				<view class="sqywh-item" v-for="item in info.historyCultures.items"
					@click="navTo('/pages/village/history/show',{id:item.id})">
					<view class="title line-1">{{item.name}}</view>
					<view class="mt-10" style="color:#666;font-size: 14px;">{{item.type}} [{{item.period}}]</view>
					<view class="mt-20 line-1" style="color:#999;font-size: 12px;">{{item.description}}</view>
				</view>
			</view>

			<!-- 景点推荐 -->
			<view class="section">
				<view class="page-title">
					<view class="text">{{info.scenicSpots.title}}</view>
					<view class="icon" @click="navTo('/pages/village/spots/index')">
						<u--text customClass="ml-auto" suffixIcon="arrow-rightward" iconStyle="font-size: 12px"
							color="#999" text="查看更多"></u--text>
					</view>
				</view>
				<view class="px-30">
					<scroll-view class="scroll-list" scroll-x="true">
						<view class="spots-item" style="width: 200px;" v-for="item in info.scenicSpots.items"
							@click="navTo('/pages/village/spots/show',{id:item.id})">
							<view class="thumb">
								<u-image width="100%" mode="aspectFill" radius="10" height="150"
									:src="item.imageUrl"></u-image>
								<view class="name">{{item.name}}</view>
								<view class="type">{{item.type}}</view>
							</view>
							<view class="info">
								<view class="description line-2">{{item.description}}</view>
							</view>

						</view>
					</scroll-view>
				</view>
			</view>
			<!-- 特色美食 -->
			<view class="section">
				<view class="page-title">
					<view class="text">{{info.foods.title}}</view>
				</view>
				<view style="display: flex;flex-wrap: wrap;margin:15rpx;">
					<view
						style="width: calc(50% - 30rpx);margin:15rpx;background-color: white;border-radius: 10px; overflow: hidden;"
						v-for="item in info.foods.items" @click="navTo('/pages/village/food/show',{id:item.id})">
						<u-image width="100%" mode="aspectFill" radius="0" height="150" :src="item.imageUrl"></u-image>
						<view style="padding:10px;">
							<view>{{item.name}}</view>
							<view class="mt-10"
								style="display: flex;align-items: center; font-size:12px;color:#999999;">
								<u-icon name="map" size="12"
									:customStyle="{marginRight:'2px'}"></u-icon><text>{{item.location}}</text>
							</view>
						</view>
					</view>
				</view>
			</view>
			<!--社区文化-->
			<view class="page-title">
				<view class="text">{{info.communityCultures.title}}</view>
				<view class="icon" @click="navTo('/pages/village/news/index')">
					<u--text customClass="ml-auto" suffixIcon="arrow-rightward" iconStyle="font-size: 12px" color="#999"
						text="查看更多"></u--text>
				</view>
			</view>
			<view class="sqywh-item" v-for="item in info.communityCultures.items"
				@click="navTo('/pages/village/community/show',{id:item.id})">
				<text class="title line-2">{{item.name}}</text>
				<view class="date"><u-icon name="calendar" color="#666" size="20"></u-icon>
					<view class="ml-10">{{item.dateOrScene}}</view>
				</view>
			</view>
			<view style="height:30rpx;"></view>

		</scroll-view>
	</view>
</template>

<script>
	import {
		getTown,
		getShiguang
	} from '@/config/api.js';
	export default {
		data() {
			return {
				navStyle: {
					paddingTop: '0px',
					height: '44px'
				},
				pageLoading: true,
				info: [],
				banner: [],
				scrollTop: 0, // 初始滚动位置
				currentSection: 0, // 当前屏的索引
			}
		},
		onLoad() {
			// #ifdef MP-WEIXIN
			// const {
			// 	barHeight,
			// 	barTop
			// } = getWXStatusHeight();
			// this.navStyle = {
			// 	paddingTop: `${barTop}px`,
			// 	height: `${barHeight}px`
			// };
			// #endif
			this.getPageData(() => {
				this.pageLoading = false;
			});
		},
		onPullDownRefresh() {
			this.getPageData(function() {
				uni.stopPullDownRefresh();
			})
		},
		methods: {
			goBack() {
				uni.navigateBack();
			},
			getPageData(cb) {
				getShiguang().then(res => {
					this.info = res;
					this.pageLoading = false;
					typeof cb == 'function' && cb();
				});
			},
			scrollToNextSection() {
				this.currentSection += 1;
				// #ifdef WEB
				let pageHeight = window.innerHeight;
				// #endif
				// #ifdef MP-WEIXIN
				let pageHeight = wx.getSystemInfoSync().windowHeight;
				// #endif
				this.scrollTop = pageHeight; // 计算滚动位置
			},
			onScroll(event) {
				// 可以在这里处理滚动事件
				console.log(event.detail.scrollTop);
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f7f7f7;
	}

	.nav {
		position: fixed;
		top: 0;
		left: 0;
		width: 100%;
		display: flex;
		align-items: center;
		z-index: 1000;
		padding: 0 20rpx;
		.back-btn {
			width: 60px;
			height:27px;
			padding: 10rpx;
			justify-content: space-around;
			display: flex;
			align-items: center;
			border-radius: 50rpx;
			color: white;
			background-color: rgba(0, 0, 0, .1);
			border: 1px solid rgba(255, 255, 255, .3);
		}

		.title {
			margin-left: 20rpx;
			font-size: 16px;
		}
	}


	.first-screen {
		height: calc(100vh - var(--window-bottom));
		background-position: center;
		background-repeat: no-repeat;
		background-size: cover;
		position: relative;

		&::after {
			content: "";
			display: block;
			background-image: linear-gradient(rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.6));
			position: absolute;
			width: 100%;
			height: 100%;
		}

		.text {
			width: 100%;
			padding: 30rpx;
			position: absolute;
			left: 0;
			bottom: 0;
			z-index: 2;

			.title {
				animation: float 1.5s infinite ease-in-out;
			}
		}

		.circle {
			width: 40px;
			height: 40px;
			border: 2px solid white;
			border-radius: 50%;
			background-color: transparent;
			position: relative;
			display: flex;
			justify-content: center;
			align-items: center;

			&>text {
				color: white;
				position: absolute;
				animation: float 2s infinite ease-in-out;
			}
		}

		@keyframes float {

			0%,
			100% {
				transform: translateY(0);
			}

			50% {
				transform: translateY(-3px);
			}
		}
	}

	.section {}

	/* 横向滚动列表样式 */
	.scroll-list {
		white-space: nowrap;
		/* 防止换行 */
		width: 100%;

		/* 列表项样式 */
		.item {
			display: inline-block;
			/* 横向排列 */

			margin-right: 10px;

			/* 图片样式 */
			.item-image {
				width: 100%;
				height: 150px;
				border-radius: 8px;
			}

			/* 标题样式 */
			.item-title {
				display: block;
				margin-top: 8px;
				font-size: 14px;
				color: #333;
			}
		}


	}


	.foods-list {
		margin-left: -15rpx;
		margin-right: -15rpx;
		display: flex;
		flex-wrap: wrap;

		.foods-item {
			width: calc(50% - 30rpx);
			margin: 15rpx;

			&:nth-child(odd) {
				.u-image {
					height: 400rpx;
				}
			}
		}
	}

	.tags {
		margin-left: -10rpx;
		margin-right: -10rpx;
		display: flex;
		flex-wrap: wrap;

		text {
			display: inline-block;
			padding: 2px 8px;
			border-radius: 5px;
			background-color: lightgoldenrodyellow;
			font-size: 20rpx;
			margin: 10rpx;
		}
	}

	.sqywh-item {
		width: calc(100% - 60rpx);
		margin-left: auto;
		margin-right: auto;
		background-color: white;
		padding: 30rpx;
		border-radius: 15px;
		padding-right: 60px;
		position: relative;

		&::after {
			font-family: remixicon !important;
			content: "\ea6e";
			position: absolute;
			right: 30rpx;
			top: 50%;
			transform: translateY(-50%);
			font-size: 32px;
			line-height: 32px;
		}

		.title {
			font-size: 16px;
			font-weight: bold;
		}

		.date {
			margin-top: 30rpx;
			font-size: 14px;
			display: flex;
			align-items: center;
			color: #666;
		}
	}

	.spots-item {
		display: inline-block;
		margin-right: 10px;
		background-color: white;
		border-radius: 5px;
		overflow: hidden;

		.thumb {
			position: relative;

			&::after {
				content: "";
				background-image: linear-gradient(to bottom, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0.8));
				position: absolute;
				z-index: 1;
				left: 0;
				top: 0;
				width: 100%;
				height: 100%;
			}

			.type {
				padding: 2px 8px;
				border-radius: 5px;
				background-color: rgba(0, 0, 0, 0.6);
				color: white;
				position: absolute;
				z-index: 2;
				top: 10px;
				right: 10px;
				font-size: 12px;
			}

			.name {
				padding: 30rpx;
				color: white;
				position: absolute;
				bottom: 0;
				left: 0;
				z-index: 2;
				font-size: 16px;
			}
		}

		.info {
			padding: 30rpx;

			.description {
				color: #999;
				font-size: 14px;
			}
		}
	}
</style>